<?php header("Content-Type:text/html;   charset=utf-8"); ?>
<script type="text/javascript">
    $(function(){
        loadEmailConfig();
        $("#btnSubmitEmail").bind('click',submitEmail);
    });

    function submitEmail(){

        var host = $("#smtp_host").val();
        var port = $("#smtp_port").val();
        //alert(111);return false;
        var protocol = $("#smtp_protocol").val();
        var email = $("#smtp_email").val();
        var user = $("#smtp_user").val();
        var pass = $("#smtp_pass").val();

        if(host == ''){
            alert('邮件服务器不能为空');
            return false;
        }

        if(email == ''){
            alert('发件人地址不能为空');
            return false;
        }

        if(user == ''){
            alert('用户名不能为空');
            return false;
        }
        if(pass == ''){
            alert('密码不能为空');
            return false;
        }

        var params = {
            smtp_host:host,
            smtp_port:port,
            smtp_protocol:protocol,
            smtp_email:email,
            smtp_user:user,
            smtp_pass:pass
        };

        $.ajax({
            type:"post",
            url:"admin.php/advertise/addEmailsetting",
            dataType:"json",
            data:params,
            success:function(data){
                loadEmailConfig();
                alert(data.msg);
            }
        });
    }

    function loadEmailConfig(){
        $.ajax({
            type:"post",
            url:"admin.php/advertise/getEmailConfig",
            dataType:"json",
            success:function(data){
                $("#smtp_host").val(data.smtp_host);
                $("#smtp_port").val(data.smtp_port);
                $("#smtp_protocol").val(data.smtp_protocol);
                $("#smtp_email").val(data.smtp_email);
                $("#smtp_user").val(data.smtp_user);
                $("#smtp_pass").val(data.smtp_pass);
            }
        });
    }

</script>
<div class="pageContent">
    <form id="formSite" class="pageForm required-validate" action="admin.php/advertise/addEmailsetting" method="post"
          enctype="multipart/form-data">
        <div class="pageFormContent" style="width: 98%;" layoutH="56">
            <input type='file' id='fileHead' name='mypic1' style='display: none'>

            <table class="tableNewUser">
                <tr>
                    <td>邮件服务器：</td>
                    <td colspan="2"><input id="smtp_host" type="text" value="" /></td>
                </tr>
                <tr>
                    <td>邮件发送端口：</td>
                    <td colspan="2"><input id="smtp_port" type="text" value="" /></td>
                </tr>
                <tr>
                    <td>邮件协议：</td>
                    <td colspan="2"><input type="text" id="smtp_protocol"></td>
                </tr>
                <tr>
                    <td>发件人地址：</td>
                    <td colspan="2"><input type="text" id="smtp_email"></td>
                </tr>
                <tr>
                    <td>验证用户名：</td>
                    <td colspan="2"><input type="text" id="smtp_user"></td>
                </tr>
                <tr>
                    <td>验证密码：</td>
                    <td colspan="2"><input type="text" id="smtp_pass"></td>
                </tr>



                <tr>
                    <td colspan="3" style='line-height: 40px'>&nbsp;&nbsp;</td>
                </tr>
            </table>
            <input type="hidden" id="hdidsite"
                   value="<?php if(isset($_GET["id"])) print $_GET["id"]; else print 0;?>">

            <div class="buttonActive" style="width: 120px; margin-left: 50px;">
                <div class="buttonContent">
                    <button id="btnSubmitEmail" type="button" style="width: 80px">提 交</button>
                </div>
            </div>

            <div class="button" style="text-align: right">
                <div class="buttonContent" style="text-align: right">
                    <button id="btnCloseEmail" type="button" class="close"
                            style="width: 80px">取 消</button>
                </div>
            </div>
        </div>
    </form>
</div>
